<template>
    <div id="web">
        <header>
            <p v-if="user.username">{{ user.username }}</p>
            <template v-else>
                <p @click="loginShow = true">登录</p>
                <p @click="loginShow = true">注册</p>
            </template>

        </header>

        <main>
            <h2>这是一句优美的中国话</h2>
            <div class="para" @copy="copy">登录以后可复制</div>
        </main>

        <div class="loginMask" v-show="loginShow" @click="loginShow = false">
            <div class="loginMenu" @click.stop>
                <input type="text" placeholder="请输入用户名" v-model="loginUser.username">
                <input type="password" placeholder="请输入密码"  v-model="loginUser.password">
                <button @click="loginShow = false" v-on:click="success">登录</button>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            user: {
                username: "",
                password: ""
            },
            loginUser:{
                username: "",
                password: ""
            },
            loginShow:false
        }
    },
    methods: {
        copy(e){
            if(!this.user.username||!this.user.password){
                e.returnValue = false;
                alert('登录后可复制');
                this.loginShow = true;
            }else{
                alert('复制成功')
            }
        },
        success(){
            this.user.username = this.loginUser.username;
            this.user.password = this.loginUser.password;
        }
    },
}
</script>

<style lang="scss">
* {
    margin: 0;
    padding: 0;
    list-style: none;
    text-decoration: none;
}

#web {
    width: 100vw;
    height: 100vh;

    header {
        display: flex;
        justify-content: flex-end;
        align-items: center;
        height: 6vh;
        padding-right: 10px;
        color: #fff;
        background-color: rgba(0, 0, 0, 0.6);

        p {
            padding: 0 10px;
            transition: color 0.1s;

            &:active {
                color: grey;
            }
        }
    }

    main {
        padding: 10px 20px;

        .para {
            margin-top: 20px;
        }
    }

    .loginMask {
        position: absolute;
        left: 0;
        top: 0;
        z-index: 999;
        width: 100vw;
        height: 100vh;
        display: flex;
        justify-content: center;
        align-items: center;
        background-color: rgba(0, 0, 0, 0.6);

        .loginMenu {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            width: 70vw;
            height: 70vh;
            padding: 20px 40px;
            box-sizing: border-box;
            border-radius: 10px;
            box-shadow: 0 0 7px 3px #fff;
            background-color: #fff;

            input {
                margin: 10px 0;
                padding: 10px 20px;
                border-radius: 10px;
                border: none;
                outline: none;
                box-shadow: 0 0 5px 0px lightgray;
                transition: all 0.3s;

                &:focus {
                    box-shadow: 0 0 5px 3px grey;
                }
            }

            button {
                margin-top: 20px;
                padding: 5px 20px;
                box-shadow: 0 0 5px 0px rgba(0, 0, 0, 0.8);
            }
        }
    }
}
</style>